/////////////////////////////////////////////////////////////////////////////////
//
//  函数传参，值传递， 引用传递
//
/////////////////////////////////////////////////////////////////////////////////
#include<iostream>

void swap(int a, int b);
void swap1(int* a,int* b);
void swap2(int& a,int& b);
void swap3(int* a,int* b);

int main(){
    printf("Hello World!\n");
    int a = 3;
    int b = 4;
    std::cout << "befor swap: a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    swap(a,b);
    std::cout << "afer swap(a,b) : a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    swap1(&a,&b);
    std::cout << "afer swap1(int* a,int* b) : a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    swap2(a,b);
    std::cout << "afer swap2(int& a,int& b) : a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    swap3(&a,&b);
    std::cout << "afer swap3(int* a,int *b) : a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    return 0;
}

void swap(int a,int b){
    std::cout << "------" << std::endl;
    std::cout << "in swap(int a,int b): a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    std::cout << "------" << std::endl;
    int temp = a;
    a = b;
    b = temp;
}
// pass by address
void swap1(int* a,int *b){
    std::cout << "------" << std::endl;
    std::cout << "in swap1(int* a,int *b): a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    int temp = *a;
    std::cout << "temp=" << temp << ", &temp=" << &temp << std::endl;
    *a = *b;
    *b = temp;
    std::cout << "------" << std::endl;
}
// pass by reference
void swap2(int& a,int& b){
    std::cout << "------" << std::endl;
    std::cout << "in swap2(int& a,int& b): a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;
    std::cout << "------" << std::endl;
    int temp = a;
    a = b;
    b = temp;
}
// pass by value ?
void swap3(int* a,int *b){
    std::cout << "------" << std::endl;
    std::cout << "in swap3(int* a,int *b): a=" << a << ", &a=" << &a << ", b=" << b << ", &b=" << &b << std::endl;

    int* temp = a;
    std::cout << "temp= " <<temp << std::endl;
    a = b;
    std::cout << "a= " <<a << std::endl;
    b = temp;
    std::cout << "b= " <<b << std::endl;
    std::cout << "------" << std::endl;
}
